<template>
  <div class="login">
    <div class="po_img">
      <el-image style="width: 230px; height: 200px" :src="url"></el-image>
    </div>
    <div class="ipts">
      <el-form
        :model="dynamicValidateForm"
        ref="dynamicValidateForm"
        label-width="100px"
        class="demo-dynamic"
      >
        <el-form-item
          prop="username"
          label="用户名"
          :rules="[
            { required: true, message: '请输入用户名', trigger: 'blur' },
            {
              min: 3,
              max: 11,
              message: '长度在 3 到 11 个字符',
              trigger: 'blur',
            },
          ]"
        >
          <el-input v-model="dynamicValidateForm.username"></el-input>
        </el-form-item>
        <el-form-item
          label="密码"
          prop="password"
          :rules="[
            { required: true, message: '请输入密码', trigger: 'blur' },
            {
              min: 3,
              max: 8,
              message: '长度在 3 到 8 个字符',
              trigger: 'blur',
            },
          ]"
        >
          <el-input
            v-model="dynamicValidateForm.password"
            show-password
          ></el-input>
        </el-form-item>
        <el-form-item class="but">
          <el-button @click="resetForm('dynamicValidateForm')">重置</el-button>
          <el-button type="primary" @click="submitForm('dynamicValidateForm')"
            >提交</el-button
          >
        </el-form-item>
      </el-form>
    </div>
  </div>
</template>

<script>
import { userLogin } from "@/request/login.js";
export default {
  name: "",
  data() {
    return {
      url: "https://se-tomo.com/wp/wp-content/uploads/2018/10/Vue.png",
      dynamicValidateForm: {
        password: "123",
        username: "admin",
      },
    };
  },
  created() {},
  mounted() {},
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          // alert("submit!");
          // console.log(this.dynamicValidateForm);
          // console.log(this.dynamicValidateForm);
          userLogin(this.dynamicValidateForm);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },
};
</script>

<style  scoped>
.login {
  width: 100vw;
  height: 100vh;
  background-color: #74d1fe;
}
.po_img {
  text-align: center;
  position: absolute;
  top: 150px;
  left: 50%;
  transform: translateX(-50%);
}
.ipts {
  width: 400px;
  position: absolute;
  top: 400px;
  left: 50%;
  transform: translateX(-58%);
}
.but {
  text-align: center;
}
</style>
